package org.dxy.trigger.listener;

import com.google.common.eventbus.Subscribe;
import lombok.RequiredArgsConstructor;
import org.dxy.domain.event.equipment.EquipmentActivatedEvent;
import org.dxy.domain.event.equipment.EquipmentStatusChangedEvent;
import org.springframework.stereotype.Component;


/**
 * @description: 监听设备激活事件，并将设备状态更新事件发布到事件总线
 * 设备激活后，发布设备状态变更事件，用于更新设备状态视图或其他相关逻辑
 * @author: dxy
 * @createTime: 2025/6/16 0:18
 */
@Component
@RequiredArgsConstructor
public class EquipmentActivatedEventListener implements EventListener<EquipmentActivatedEvent>{


    /**
     * 处理设备激活事件
     * @param event 设备激活事件，包含设备ID等信息
     */
    @Subscribe
    @Override
    public void onEvent(EquipmentActivatedEvent event) {
        EquipmentStatusChangedEvent statusEvent = EquipmentStatusChangedEvent.builder()
                .equipmentId(event.getEquipmentId())
                .previousStatus(event.getPreviousStatus())
                .currentStatus(event.getCurrentStatus())
                .workOrderId(null)  // 如果有可填充
                .position(null)     // 如果有可填充
                .changedTime(event.getActivatedTime())
                .build();
//        eventBus.post(statusEvent);
    }
}
